package bavaria.hightech.banking;





import java.util.Calendar;

import bavaria.hightech.conditions.FixedConditions;
import bavaria.hightech.conditions.Conditions;
import bavaria.hightech.exception.MoneyLauderingException;
import bavaria.hightech.exception.NoMoneyEcxeption;
import bavaria.hightech.money.Currency;
import bavaria.hightech.money.Money;
import bavaria.hightech.time.InteranlClock;



public class FixedDepositAccount extends Account {
	private FixedConditions conditions;
	private Calendar intrestDate;

	public FixedDepositAccount(String accountOwner, int accountNumber, Currency curr, FixedConditions fixedConditions){
		super(accountOwner,accountNumber, curr);
		this.conditions = fixedConditions;
		
		setIntrestDate();
		
	}

	@Override
	public void toPayIntrestOn() {
		
		if(InteranlClock.getInstanze().getCalendar().after(intrestDate)){
		Money intrest = new Money((long)(getAccountBalance() * (conditions.getFixedRateOfIntrest()/100)), getCurrency());
		try {
			access(intrest, "Haben Zinsen");
		} catch (MoneyLauderingException e) {
			e.printStackTrace();
		}
		System.out.println("Fesltgeld Zinsen");
		setIntrestDate();
		}
		}
	
	@Override
	public void withdraw(Money amount, String refernece) throws NoMoneyEcxeption{
			if(getAccountBalance() < amount.getValue())
				throw new NoMoneyEcxeption("Zu wenig Geld auf dem Konto");
			else
				super.withdraw(amount, refernece);
	}
	

	@Override
	public void getConditions() {
		
		System.out.println("Laufzeit in Monaten: "+conditions.getTenorFixedAccount()+ " Zinssatz: "+conditions.getFixedRateOfIntrest());
		
	}

	
	public int tenor() {	
		return conditions.getTenorFixedAccount();
	}
	
	public void setIntrestDate(){
		Calendar intrestDate =  getDate();
		int c = 1;
		intrestDate.add(Calendar.MONTH, (tenor()*c));
		this.intrestDate = intrestDate;
		c++;
	}
	
	public Calendar getIntrestDate(){
		return intrestDate;
	}
}

